const http = require('http')
const fs = require('fs')
const path = require('path')

const sever = http.createServer((request, response) => {
  let { pathname } = new URL(request.url, 'http://127.0.0.1:9000')
  if(pathname === '/') {
    fs.readFile(path.resolve(__dirname, 'table.html'), (error, data) => {
      if(error) {
        console.log('table.html文件读取失败', error)
        return
      }
      response.end(data)
    })
  } else if(pathname === '/table.css') {
    const data = fs.readFileSync(path.resolve(__dirname, 'table.css'))
    response.end(data)
  } else if(pathname === '/table.js') {
    const data = fs.readFileSync(path.resolve(__dirname, 'table.js'))
    response.end(data)
  } else {
    response.statusCode = 404
    response.end('找不到资源')
  }
})

sever.listen(9000, () => {
  console.log('9000端口监听中。。。')
})